#include <iostream>
#include <conio.h>
#include "TicTacToe.h"

void startTurn( TicTacToe& game, int& turn );

int main()
{
	TicTacToe game;
	int turn = 0;

	game.getGrid(2,2);

	game.drawBoard(3,3);
	Course::Console::setcursor(1,100);
	Course::Console::gotoxy(3,3);

	while( true )
	{
		for( int turns = 0; turns < 9; )
		{
			turns += 1;
			startTurn( game, turn );
			int winType = game.detectGameOver();
			if( winType < 3 )
			{
				game.printWinner( game.detectWinner( winType ) );
				cin.get();
				return 0;
			}
		}
		Course::Console::clrscr();
		Course::Console::gotoxy(10,5);
		cout << "Game Over, it's a draw" << endl;
		cin.get();
		return 0;
	}
	return 0;
}

void startTurn( TicTacToe& game, int& turn )
{
	game.setTurnNotOver( true );
	while( game.getTurnNotOver() )
	{
		int input;
		input = _getch();
	
		if( input == 224 )
		{
			input = _getch();
		}
		
		game.drawMark( input, turn );

		game.moveCursor( input );
	}

}